package com.lingfengerick.commons.verification;

import com.lingfengerick.commons.constant.ConstantEnum;

import java.util.regex.Pattern;

/**
 * 正则校验工具类
 * @author lingfengerick
 * @since 2021/8/8 9:41 下午
 */
public class RegularVerificationUtils {

    /**
    *
    * @author lingfengerick
    * @since 2021/8/8  10:10 下午
    * @param  phoneNum 手机号
    * @return boolean
    *
    */
    public static boolean checkPhoneNum(String phoneNum){
        return verification(phoneNum , ConstantEnum.PHONE_NUM);
    }

    /**
    *
    * @author  lingfengerick
    * @since 2021/8/8  10:18 下午
    * @param email 校验邮箱
    * @return boolean
    *
    */
    public static boolean checkEmailAdress(String email){
        return verification(email , ConstantEnum.EMAIL);
    }

    /**
    *
    * @author  lingfengerick
    * @since 2021/8/8  10:23 下午
    * @param identityNum 身份证号
    * @return boolean
    *
    */
    public static boolean checkIdentityNum(String identityNum){
        return verification(identityNum , ConstantEnum.IDENTITY_PATTERN_FORMAT);
    }

    /**
    *
    * @author  lingfengerick
    * @since 2021/8/9  9:33 下午
    * @param checkParsm 校验字符串
    * @return boolean
    *
    */
    public static boolean checkPwdComplex(String checkParsm){
        return verification(checkParsm , ConstantEnum.PASSWORD);
    }

    /**
    *
    * @author  lingfengerick
    * @since   2021/8/9  9:39 下午
    * @param checkParam 校验字符
    * @return boolean
    *
    */
    public static boolean checkAllNum(String checkParam){
        return verification(checkParam , ConstantEnum.ALL_NUM);
    }

    /**
    *
    * @author  lingfengerick
    * @since 2021/8/9  9:50 下午
    * @param checkParam 校验字符
    * @return boolean
    *
    */
    public static boolean checkChineseChar(String checkParam){
        return verification(checkParam , ConstantEnum.CHINESE_CHAR);
    }

    /**
    *
    * @author  lingfengerick
    * @since 2021/8/8  10:11 下午
    * @param strParam 需要校验的字符串
    * @param constantEnum 正则表达式对应的枚举
    * @return boolean
    *
    */
    private static boolean verification(String strParam , ConstantEnum constantEnum){
        return Pattern.matches(constantEnum.getEnumValue(), strParam);
    }

    /**
    *  正则表达式校验相应的格式
    * @author  lingfengerick
    * @since 2022/5/4  10:37 AM
    * @param sourceParam 需要校验的字符串
    * @param patternType 正则规则
    * @return 是否符合
    *
    */
    public static boolean verification(String sourceParam , String patternType){
        return Pattern.matches(patternType, sourceParam);
    }

}
